package columns

import (
	"GraduationProject/public/db"
	"GraduationProject/public/models"
	"GraduationProject/webserver/controllers/util"
	"github.com/gin-gonic/gin"
)

func Get(c *gin.Context) {
	_, err := util.UserFilter(c)
	if err != nil {
		return
	}

	seedID, err := util.PostFormInt(c, "seed_id")
	if err != nil {
		return
	}

	var columns models.Columns
	if err := db.DB.Where("seed_id = ?", seedID).
		Last(&columns).Error; err != nil {
		util.FailedResponse(c, 10001, "无此排版")
		return
	}

	c.JSON(200, gin.H{
		"status":  10000,
		"message": "success",
		"columns": columns,
	})
}
